﻿@model PagerDutyIncidentModel
@{
    this.SetPageTitle("PagerDuty Incident Detail");
    var i = Model.Incident;
    var acknowledgedBy = await i.GetAcknowledgedByAsync();
    var resolvedBy = await i.GetResolvedByAsync();
}
<h4 class="modal-title">
    Incident @i.Number.ToString()@if (i.Title.HasValue()){<text>: @i.Title</text>}
</h4>
<div>
    <div class="row small">
        <div class="value-block col-md-6">
            @i.AffectedService.Name
            <label>Service</label>
        </div>
        <div class="value-block col-md-6">
            <a href="@i.Uri" target="_blank">@(i.Uri.Split('/').Last())</a>
            <label>Link</label>
        </div>
    </div>
    <div class="row small">
        <div class="value-block col-md-4">
            @if (acknowledgedBy?.Any() ?? false)
            {
                @(acknowledgedBy.First().AckPerson)
            }
            else
            {
                <span class="text-muted">Not Ackonwledged</span>
            }
            <label>Acknowledged By</label>
        </div>
        <div class="value-block col-md-4 @i.MonitorStatus.BackgroundClass()" title="@i.ResolveReason">
            @(resolvedBy)
            @if (resolvedBy == null)
            {
                <span class="text-muted">Unresolved</span>
            }
            <label>Resolved By</label>
        </div>
        <div class="value-block col-md-4">
            @if (i.LastChangedBy != null)
            {
                @:@i.LastChangedBy.Summary - @(i.LastChangedOn?.ToRelativeTimeSpan())
            }
            else
            {
                <span class="text-muted">No Changes</span>
            }
            <label>Last Change</label>
        </div>
    </div>

    <h5 class="page-header">Incident Log</h5>
    <table class="table table-striped table-hover table-responsive text-nowrap table-super-condensed">
        <thead>
        <tr>
            <th>Time</th>
            <th>Type</th>
            <th>Message</th>
            <th>Notes</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var l in Model.Logs)
        {
            var type = l.LogType?.Replace("_log_entry", "").ToTitleCase();
            <tr>
                <td>@(l.CreationTime?.ToRelativeTimeSpan())</td>
                <td>
                    @if (l.Url.HasValue())
                    {
                        <a href="@l.Url">@type</a>
                    }
                    else
                    {
                        @type
                    }
                </td>
                <td>@l.Summary</td>
                <td>@l.Note</td>
            </tr>
        }
        </tbody>
    </table>
</div>